<?php
namespace app\index\controller;

use think\Controller;
use think\Request;


//微信支付
class Wepay extends Controller{
	
	
	//发起微信支付
	public function index(){

		$param = [
			'body' =>Request::instance()->param('body'),
			'orderid' =>Request::instance()->param('orderid'),
			'pay_no' =>Request::instance()->param('pay_no'),
			'price' =>Request::instance()->param('price'),
			'notify_url' =>Request::instance()->param('notify_url'),
		];
		
		Vendor('weixinpay.do.JSAPI2');
		$hp = new \JSAPI2();
		
		list($jsApiParameters,$editAddress) = $hp->GetParam($param['body'],$param['pay_no'],$param['price'],$param['notify_url']);
		//var_dump($param); exit;
		//var_dump($jsApiParameters);
		//var_dump($editAddress);
		//exit;
		
		return view('',[
			'orderid'=>$param['orderid'],
			'jsApiParameters'=>$jsApiParameters,
			'editAddress'=>$editAddress
		]);
	}
	
	//异步通知
	public function notify_url(){
		
    //__log(json_encode($_POST,JSON_UNESCAPED_UNICODE),'wepay_notify');
    
		Vendor('weixinpay.do.NOTIFY2');
		$hp = new \NOTIFY2();
		$hp->Start();
	}
	
	//支付完毕，点完成按钮进入该页面
	public function return_url(){
		
		$orderid = Request::instance()->param('orderid');
		
		$this->redirect('Order/pay',['orderid'=>$orderid]);
	}
	

}
